package erfgame.core.graphics.renderer.animation;

public class AnimationCycle {
    
    private int cycleTime;
    private int[] stepTimes;
    
    public AnimationCycle(int cycleTime, int numSteps) {
        int[] stepTimes = new int[numSteps];
        int stepTime = cycleTime / numSteps;
        for( int i=0; i<numSteps-1; i++ ) {
            stepTimes[i] = stepTime;
        }
        // hacky way to deal with rounding errors
        stepTimes[numSteps-1] = cycleTime - ( stepTime * (numSteps-1) );
        this.stepTimes = stepTimes;
        this.cycleTime = cycleTime;
    }
    
    public AnimationCycle(int[] stepTimes) {
        this.stepTimes = stepTimes;
        for( int i = stepTimes.length; i>0; ) {
            i--;
            cycleTime += stepTimes[i];
        }
    }
    
    public int getCycleTime() {
        return this.cycleTime;
    }
    
    public int[] getStepTimes() {
        return this.stepTimes;
    }
    
    public int getCycleProgress( long activityTime ) {
        return (int)(activityTime % cycleTime);
    }
}
